package com.example.administrator.myapplication.base;


import com.aurelhubert.ahbottomnavigation.AHBottomNavigation;
import com.aurelhubert.ahbottomnavigation.AHBottomNavigationItem;
import com.example.administrator.myapplication.R;
import com.example.administrator.myapplication.utils.DrawableUtils;
import com.example.administrator.myapplication.view.HomeActivity;
import com.example.administrator.myapplication.view.InformationActivity;
import com.example.administrator.myapplication.view.MyActivity;
import com.example.administrator.myapplication.view.RecordActivity;

import butterknife.BindView;

/**
 * Created by lyxs9 on 2017/5/4.
 */

public abstract class BaseMainActivity extends BaseActivity implements AHBottomNavigation.OnTabSelectedListener {
    @BindView(R.id.bottom_navigation_bar)
    AHBottomNavigation ahBottomNavigation;

    @Override
    public void initView() {
        ahBottomNavigation.setAccentColor(getResources().getColor(R.color.main_color));

        ahBottomNavigation.addItem(new AHBottomNavigationItem(getResources().getString(R.string.bottom_1),
                DrawableUtils.getStateSelectDrawable(R.mipmap.sys, R.mipmap.sys)));

        ahBottomNavigation.addItem(new AHBottomNavigationItem(getResources().getString(R.string.bottom_2),
                DrawableUtils.getStateSelectDrawable(R.mipmap.ic_record, R.mipmap.ic_record)));


        ahBottomNavigation.addItem(new AHBottomNavigationItem(getResources().getString(R.string.bottom_4),
                DrawableUtils.getStateSelectDrawable(R.mipmap.information, R.mipmap.information)));


        ahBottomNavigation.addItem(new AHBottomNavigationItem(getResources().getString(R.string.bottom_3),
                DrawableUtils.getStateSelectDrawable(R.mipmap.ic_person, R.mipmap.ic_person)));


        ahBottomNavigation.setDefaultBackgroundColor(getResources().getColor(R.color.white));
        ahBottomNavigation.setCurrentItem(currentItem(), true);
        ahBottomNavigation.setForceTitlesDisplay(true);
        ahBottomNavigation.setOnTabSelectedListener(this);
        ahBottomNavigation.setBehaviorTranslationEnabled(true);




//        ahBottomNavigation.setNotification("1",3);
//        ahBottomNavigation.setNotification("36",2);
    }


    @Override
    public boolean onTabSelected(int position, boolean wasSelected) {
        if (position != currentItem()) {

            if (position == 0) {
                HomeActivity.startUI(this);
            } else if (position == 1) {
                RecordActivity.startUI(this);
            } else if (position == 2) {
                InformationActivity.startUI(this);
            } else if (position == 3) {
                MyActivity.startUI(this);

            }
        }
        return true;
    }

    @Override
    protected void onResume() {
        super.onResume();
        ahBottomNavigation.setCurrentItem(currentItem(), false);
    }

    public abstract int currentItem();
}
